package com.bitin.adorn.modules.system.api;

import com.bitin.adorn.modules.system.domain.Department;
import com.bitin.adorn.modules.system.service.DepartmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author Mr.Lu
 * @since 2024/6/5 15:27
 */
@Tag(name = "部门")
@RestController
@RequestMapping("/v1/department")
@AllArgsConstructor
@Slf4j
public class DepartmentController {
    private final DepartmentService departmentService;

    @Operation(summary = "部门-列表")
    @GetMapping("/list")
    public Object list() {
        return departmentService.list();
    }

    @Operation(summary = "部门")
    @GetMapping("/one")
    public Object one(Long id) {
        return departmentService.findById(id);
    }

    @Operation(summary = "部门-新增", description = "新增部门")
    @PostMapping("/save")
    public Object save(@RequestBody Department department) {
        return departmentService.save(department);
    }

    @Operation(summary = "部门-删除")
    @DeleteMapping("/{id}")
    public void remove(@PathVariable("id") Long id) {
        departmentService.deleteById(id);
    }

    @Operation(summary = "子部门-新增", description = "新增子部门")
    @PutMapping("/{id}/add/child")
    public Object addChild(@PathVariable("id") Long id, @RequestBody Department department) {
        return departmentService.addChild(id, department);
    }

    @Operation(summary = "子部门-移除", description = "移除子部门")
    @PutMapping("/{id}/remove/{childId}/child")
    public Object removeChild(@PathVariable("id") Long id, @PathVariable("childId") Long childId) {
        return departmentService.removeChild(id, childId);
    }
}
